package hot;


import java.util.HashSet;
import java.util.Set;

/**
 * @author lakersUp
 * @Classname
 * @Description
 * @Date 2022/3/12 9:28
 * @Version 1.0
 */
public class Hot128longestConsecutive {
    public int longestConsecutive(int[] nums) {
        Set<Integer> set=new HashSet<>();
        int max=0;
        for (int num : nums) {
            set.add(num);
        }
        for(int i=0;i<nums.length;i++){
            if(!set.contains(nums[i]-1)){
                int currentNum=nums[i];
                int currentLongest=1;
                while(set.contains(currentNum+1)){
                    currentNum+=1;
                    currentLongest+=1;
                }
                max=Math.max(max,currentLongest);
            }
        }
        return max;
    }
}
